package cn.hd01.repository;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import cn.hd01.repository.entity.CustomerBankCard;

@Repository
public interface CustomerBankCardRepository extends JpaRepository<CustomerBankCard, Integer> {

	Page<CustomerBankCard> findAll(Specification<CustomerBankCard> spec, Pageable pageable);
	
	List<CustomerBankCard> findByCustomerId(Integer customerId);
	
	CustomerBankCard findByCustomerIdAndIsDefault(Integer customerId, Boolean isDefault);
	
	@Modifying
	@Transactional
	@Query("delete from CustomerBankCard where customerId = ?1")
	void deleteByCustomerId(Integer customerId);
}
